﻿using OnHook.Business.IServices;
using OnHook.Domain.Entities;
using OnHook.Framework.Ioc;
using SqlSugar;

namespace OnHook.Business.Services
{
    /// <summary>
    /// 订单日志
    /// </summary>
    public class OrderLogService(ISqlSugarClient db) : IOrderLogService,IScoped
    {
        private readonly ISqlSugarClient _db = db;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="log"></param>
        /// <returns></returns>
        public async Task AddOrderLogAsync(OrderLog log) =>await _db.Insertable(log).ExecuteCommandAsync();

        /// <summary>
        /// 
        /// </summary>
        /// <param name="order"></param>
        /// <param name="operate"></param>
        /// <returns></returns>
        public async Task AddOrderLogAsync(Order order, string operate) => await AddOrderLogAsync(new OrderLog(order.OrderId, operate, order.UserId));
        /// <summary>
        /// 
        /// </summary>
        /// <param name="orderid"></param>
        /// <param name="operate"></param>
        /// <param name="userid"></param>
        /// <param name="result1"></param>
        /// <param name="result2"></param>
        /// <returns></returns>
        public async Task AddOrderLogAsync(string orderid, string operate, long userid, string result1 = "", string result2 = "") 
            =>await AddOrderLogAsync(new OrderLog(orderid, operate, userid) { OrderResult1 = result1, OrderResult2 = result2 });

    }
}
